cmake_minimum_required(VERSION 3.31)


# 设置项目中加入全局预编译
add_definitions(-D LOG_DEBUG)           # 普通日志开关
add_definitions(-D GL_CHECK_DEBUG)        # OpenGL状态相关日志开关


set(PROJECT_NAME "GLRenderEngine")
project(${PROJECT_NAME})
message(STATUS "PROJECT_NAME: ${PROJECT_NAME}")

set(CMAKE_CXX_STANDARD 17)
set(ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "ROOT_PATH: ${ROOT_PATH}")


# 设置 GLAD 路径
set(GLAD_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdParty/include/glad)
set(GLAD_SOURCE ${CMAKE_SOURCE_DIR}/source/glad.c)
set(GLFW_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdParty/include/GLFW)
set(GLFW3_LIB_DIR ${CMAKE_SOURCE_DIR}/thirdParty/libs/glfw3)
message(STATUS "GLAD_INCLUDE_DIR: ${GLAD_INCLUDE_DIR}")
message(STATUS "GLAD_SOURCE: ${GLAD_SOURCE}")
message(STATUS "GLFW_INCLUDE_DIR: ${GLFW_INCLUDE_DIR}")
message(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
message(STATUS "GLFW3_LIB_DIR: ${GLFW3_LIB_DIR}")


# asset资源拷贝 (用于减少包体积，运行时候从对应的根目录下拉去对应的静态资源)
# 把需要拷贝的资源路径都放到ASSETS里
file(GLOB ASSETS ./assets)
# 把ASSETS指代的目录集合的内容，拷贝到可执行文件目录下  CMAKE_BINARY_DIR：内置变量，代表可执行程序的目录地址
file(COPY ${ASSETS} DESTINATION ${CMAKE_BINARY_DIR})
message(STATUS "BINARY_DIR: ${CMAKE_BINARY_DIR}")



# 添加头文件搜索, 告诉编译器从什么目录中找到相应的资源文件 (静态库)
# include_directories(SYSTEM ${ROOT_PATH}/thirdParty/include)
# 添加头文件搜索, 告诉编译器从什么目录中找到相应的资源文件 (静态库)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/include)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/demo)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/application)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/glFramework)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/global)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/imgui)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/math)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/utils)
include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/wrapper)

# 添加需要链接的lib库地址
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/libs/glfw3)

message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")

# 添加子模块
add_subdirectory(application)
add_subdirectory(glFramework)
add_subdirectory(wrapper)
add_subdirectory(utils)
add_subdirectory(global)
add_subdirectory(imgui)

# 工程的主程序文件以及输出的程序名称
add_executable(${PROJECT_NAME}
        source/glad.c
        main.cpp
)


# 本地库
target_link_libraries(${PROJECT_NAME}
    APPLICATION_LIBS
    GLFRAMEWORK_LIBS
    UTILS_LIBS
    WRAPPER_LIBS
    GLOBAL_LIBS
    IMGUI_LIB
)

# 三方库 （会从我们链接的lib找下面的文件）
target_link_libraries(${PROJECT_NAME}
        libglfw3.a
        libglfw3dll.a
)